//:C06:SpecialList.cpp
// Using the second version of transform().
#include <algorithm>
#include <ctime>
#include <iterator>
#include <vector>
#include "Inventory.h"
#include "PrintSequence.h"
using namespace std;

struct Discounter
{
    Inventory operator()(const Inventory& inv,
      float discount)
    {
        return Inventory(inv.getItem(), inv.getQuantity(),
          int(inv.getValue() * (1 - discount)));
    }
};

struct DiscGen
{
    float operator()()
    {
        float r = float(rand() % 10);
        return r / 100.0;
    }
};

int main(void)
{
    vector<Inventory> vi;
    srand(time(0));
    generate_n(back_inserter(vi), 15, InvenGen());
    print(vi.begin(), vi.end(), "vi");
    vector<float> disc;
    generate_n(back_inserter(disc), 15, DiscGen());
    print(disc.begin(), disc.end(), "Discounts:");
    vector<Inventory> discounted;
    transform(vi.begin(), vi.end(), disc.begin(), back_inserter(discounted), 
    Discounter());
    print(discounted.begin(), discounted.end(), "discounted");
}